const fs = jest.genMockFromModule("fs")
const _fs = jest.requireActual("fs")

Object.assign(fs, _fs)

let readMocks = {}
fs.setReadFileMock = (path, error, data) => {
  readMocks[path] = [error, data]
}
fs.readFile = (path, options, callback) => {
  if (callback === undefined) {callback = options}
  if (path in readMocks) {
    // callback(mocks[path][0],mocks[path][1])
    callback(...readMocks[path])
  } else {
    _fs.readFile(path, options, callback)
  }
}


let writeMocks={}

fs.setWriteFileMock=(path,fn)=>{
  writeMocks[path]=fn
}
fs.writeFile = (file, data, options, callback) => {
  if (callback === undefined) {callback = options}
  if(path in writeMocks){
    writeMocks[path](file,data,options,callback)
  }else{
    _fs.writeFile(file,data,options,callback)
  }
}

fs.clearMocks=()=>{
  readMocks={}
  writeMocks={}
}
module.exports = fs